Skip to content

Comments

Feature/opencode integration#225

Open
AlecMcQuarrie wants to merge 3 commits intortk-ai:masterfrom
AlecMcQuarrie:master
Open

Feature/opencode integration#225
AlecMcQuarrie wants to merge 3 commits intortk-ai:masterfrom
AlecMcQuarrie:master

Conversation

@AlecMcQuarrie
Copy link

Add support for opencode's plugin layout.

AlecMcQuarrie and others added 3 commits February 19, 2026 17:37
Add RTK support for OpenCode alongside existing Claude Code integration.
OpenCode users can now install RTK via its native plugin system for
transparent command rewriting and token optimization.

New files:
- hooks/opencode-rtk-plugin.ts: TypeScript plugin that ports the bash
  rewrite logic to OpenCode's tool.execute.before hook
- hooks/opencode-rtk-awareness.md: Slim awareness doc for OpenCode
- hooks/opencode-rtk-rules.md: Rules file for OpenCode's rules system

CLI changes:
- rtk init --opencode [-g]: Install plugin + rules for OpenCode
- rtk init --opencode --show: Show OpenCode RTK configuration
- rtk init --opencode --uninstall [-g]: Remove OpenCode RTK artifacts
- rtk discover --opencode: Scan OpenCode sessions for missed savings

Implementation:
- OpenCode plugin uses tool.execute.before event to intercept and
  rewrite bash commands (same patterns as rtk-rewrite.sh)
- OpenCodeProvider in discover module supports session scanning
- All 418 tests pass, no new clippy errors
@pszymkowiak
Copy link
Collaborator

Great work on this, thanks for the effort! The Rust code is clean, 418 tests pass, and all existing commands work fine.

We have one architectural concern we'd like to discuss before merging.

The TypeScript plugin reimplements rewrite logic that should live in Rust.

hooks/opencode-rtk-plugin.ts is 309 lines of regex-based command rewriting — the same logic that exists in hooks/rtk-rewrite.sh (bash) and will soon be native Rust via PR #150 (rtk
hook-rewrite). This means rewrite logic maintained in 3 places, and the TS version already diverges (it rewrites cat, grep, find, diff which the bash hook intentionally skips because the
argument interfaces are incompatible).

Proposed architecture: rtk hook-rewrite as universal entry point

Once PR #150 merges, every integration should call the same Rust binary:

Claude Code → hook (JSON) → rtk hook-rewrite
OpenCode → plugin (TS) → rtk hook-rewrite
Gemini CLI → hook (bash) → rtk hook-rewrite
Codex → hook (TBD) → rtk hook-rewrite

OpenCode's tool.execute.before hook https://opencode.ai/docs/plugins/, so the plugin could be ~10 lines:
hooks: {
"tool.execute.before": async (input) => {
const result = await $rtk hook-rewrite ${input.command};
return { ...input, command: result.text() };
}
}

Single source of truth in Rust, zero divergence, trivial to add new providers.

Other notes:

  • rtk discover --opencode silently returns zero results for all users — OpenCode uses SQLite but the provider only reads JSONL
  • The rtk init --opencode installer and README docs are good and can be reused as-is

Suggestion: Wait for PR #150 to merge, then resubmit with a minimal plugin calling rtk hook-rewrite. We're open to discussing the approach — happy to help shape this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants